package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.baoding.api.bean.AllCoupon
import client.comm.baoding.ui.viewmodel.MiddleVm

class AllCouponlistViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)

    val isOneLoading = MutableLiveData<Boolean>(false)
    val callOne = MutableLiveData<JsonResult<AllCoupon>>()
    val getRet = MutableLiveData<JsonResult<Ret>>()

    fun holdOne() {
        if (isOneLoading.value!!)
            return
        hold({
            server.all_coupon()
        }, {
            isOneLoading.value = true
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun getObtain(id: String) {
        hold({
            server.get_coupons(id)
        }, {
            isShowing.value = true
        }, {
            getRet.value = it
        }, complete = {
            isShowing.value = false
        })
    }
}